package great.project.common.oss2;

public enum MediaType {
    /**
     * 图片
     */
    PNG("png" , "image/png"),
    JPG("jpg","image/jpeg"),
    JPEG("jpeg","image/jpeg"),
    ICO("ico","image/x-icon"),
    GIF("gif","image/gif"),
    PPT("ppt","application/x-ppt"),
    /**
     * 媒体
     */
    MP4("video", "audio/mp4"),
    BMP("bmp","application/x-bmp"),
    ZIP("zip","application/zip"),
    JSON("json","application/json"),
    AVI("avi" , "video/avi"),
    PDF("pdf", "application/pdf");

    private final String value;
    private final String contentType;

    MediaType(String value , String contentType) {
        this.value = value;
        this.contentType = contentType;
    }

    /**
     *  获取 媒体类型的 contentType .
     * @param suffix 文件的后缀名 （不要带上点 例如 xx.mp4 只需要传 mp4 即可，不要传 .mp4）
     * @return contentType
     */
    public static String getContentType(String suffix){
        MediaType[] values = values();
        for (MediaType mediaType : values) {
            if (mediaType.value.equals(suffix)) {
                return mediaType.contentType;
            }
        }
        return null;
    }



    public String getValue() {
        return value;
    }
}
